//package com.xucy.springboot.shiro;
//
//import org.apache.shiro.mgt.DefaultSecurityManager;
//import org.apache.shiro.mgt.SecurityManager;
//import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
//import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
//import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
//import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.LinkedHashMap;
//
///**
// * @Author xucy
// * @Date 2019-09-01 18:01
// * @Description
// **/
//
//@Configuration
//public class ShiroConfiguration {
//
//    @Bean
//    public ShiroFilterFactoryBean shiroFilterFactoryBean(@Qualifier("securityManager") SecurityManager securityManager){
//        ShiroFilterFactoryBean shiroFilterFactoryBean=new ShiroFilterFactoryBean();
//        shiroFilterFactoryBean.setSecurityManager(securityManager);
//        shiroFilterFactoryBean.setLoginUrl("/login");
//
//        shiroFilterFactoryBean.setSuccessUrl("/index");
//
//        shiroFilterFactoryBean.setUnauthorizedUrl("/unauthrized");
//
//
//        //定义shiro权限  定义的 authc anon 都是shiro中DefaultFilter中的内容，指定，
//        //  符合index的路径，交给authc的filter来过滤
//        LinkedHashMap<String,String> filterMap=new LinkedHashMap<>();
//        filterMap.put("/index","authc");
//        filterMap.put("/login","anon");
//
//        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterMap);
//        return shiroFilterFactoryBean;
//
//    }
//
//    @Bean("securityManager")
//    public SecurityManager securityManager( @Qualifier("authRealm") AuthRealm authRealm){
//        DefaultWebSecurityManager securityManager=new DefaultWebSecurityManager();
//        securityManager.setRealm(authRealm);
//        return securityManager;
//    }
//
//
//    @Bean("authRealm")
//    public AuthRealm authRealm(@Qualifier("credentialMatcher") CredentialMatcher credentialMatcher){
//        AuthRealm authRealm=new AuthRealm();
//        authRealm.setCredentialsMatcher(credentialMatcher);
//        return authRealm;
//    }
//
//
//    @Bean("credentialMatcher")
//    public CredentialMatcher credentialMatcher(){
//        return new CredentialMatcher();
//    }
//
//
//    //设置spring 与shiro的关联对象
//    @Bean
//    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(@Qualifier("securityManager") SecurityManager securityManager){
//        AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor=new AuthorizationAttributeSourceAdvisor();
//        authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
//
//        return authorizationAttributeSourceAdvisor;
//
//    }
//
//    @Bean
//    public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator(){
//        DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator=new DefaultAdvisorAutoProxyCreator();
//        defaultAdvisorAutoProxyCreator.setProxyTargetClass(true);
//
//        return defaultAdvisorAutoProxyCreator;
//    }
//}
